﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
  
</head>
<body>
            <div class="demo-login-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">物料编码</label>
                    <div class="layui-input-block">
                        <select name="interest" id="materialId" lay-filter="aihao" onchange="MaterialFull()" style="width:100%;height:30px">
                            <option value=-1>请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">物料名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" id="materialName" lay-verify="required"  disabled placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">规格型号</label>
                    <div class="layui-input-block">
                <input type="text" name="username" disabled id="specificationModel" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">单位</label>
                    <div class="layui-input-block">
                <input type="text" name="username" disabled id="unit" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">调拨数量</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" id="allocateCount" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">库存数量</label>
                    <div class="layui-input-block">
                <input type="text" name="username" disabled id="inventoryCount" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label class="layui-form-label">摘要</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" id="summary" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-primary layui-border" onclick="layer.close(index1)">返回</button>
                    <button type="button" class="layui-btn layui-bg-blue" onclick="InventoryDetailAdd()">确定</button>
                </div>
            </div>
    <script>
        layui.use(['form', 'laydate', 'util'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
          
        });


    </script>

</body>
</html>
<script>
    //绑定下拉框
    //物料编码
    MaterialSelect()
    function MaterialSelect() {
        $.get({
            url: '@ViewBag.RBACWrite' + "/api/Inventory/MaterailFull?Id=" + -1,
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                $.each(res.data, function () {
                    $("#materialId").append(`<option value="${this.materialId}">${this.materialCode}</option>`)
                })
            }
        })
    }

    //反填操作
    function MaterialFull() {
        $.get({
            url: '@ViewBag.RBACWrite' + "/api/Inventory/MaterailFull?Id=" + $("#materialId").val(),
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                console.log(res.data);
                $("#materialName").val(res.data[0].materialName)
                $("#specificationModel").val(res.data[0].specifications)
                $("#unit").val(res.data[0].packagingSpecifications)
                $("#inventoryCount").val(res.data[0].inventoryLowerLimit)
            }
        })
    }

    function ResouresList() {
        console.log(id);
        $.get({
            url: '@ViewBag.RBACWrite' + "/api/Process/ResourcesList?WorkCenterId=" + id,
            async: false,
            dataType: "json", 
            contentType: "application/json",
            success: res => {
                console.log(res, "111");
                $.each(res.data, function () {
                    $("#ProcessDetailName").append(`<option value="${this.resourceId}">${this.resourceName}</option>`)
                })
            }
        })
    }
    //库存调拨资源新增
    function InventoryDetailAdd() {
        var data = {
            allocateNumber :localStorage.getItem("allocateNumber"),
            materialId: $("#materialId").val(),
            materialName: $("#materialName").val(),
            specificationModel: $("#specificationModel").val(),
            unit: $("#unit").val(),
            allocateCount: $("#allocateCount").val(),
            inventoryCount: $("#inventoryCount").val(),
            summary: $("#summary").val(),
        }
        $.post({
            url: '@ViewBag.RBACWrite' + "/api/Inventory/InventoryDetailAdd",
            data: JSON.stringify(data),
            async: false,
            dataType: "Json",
            contentType: "application/json",
            success: res => {
                if (res.code == 1) {
                    layer.alert("新增成功");
                    return;
                }
                else {
                    layer.alert("新增失败");
                    return;
                }
            }
        })
    }
</script>

